package designpattern.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO:类描述
 *
 * @className: Teacher
 * @packageName: designpattern.observer
 * @author: Zhuhj
 * @version: V1.0
 * @date: 2021/4/18 22:12
 */
public class Teacher implements ISubject{
    private String phone ;
    private List<IObserver> list = new ArrayList<>(5);
    @Override
    public void regObserver(IObserver iObserver) {
        list.add(iObserver);
    }

    @Override
    public void removerObserver(IObserver iObserver) {
        list.remove(iObserver);
    }

    @Override
    public void notifyObeserver() {
        list.forEach(obj->{
            obj.update(this.getPhone());
        });
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
        notifyObeserver();
    }
}
